<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>部门表单</title>
  <link rel="stylesheet" href="${ctx}/static/admin/layui/css/layui.css">
  </head>
    <body>
    <div class="layui-card-body">
  	<form class="layui-form layui-form-pane" lay-filter="resform">
	  <input name="id" type="hidden" value="${res.id! }" />
	  <input name="pid" type="hidden" value="${res.pid! }" />
	  <div class="layui-form-item">
	    <label class="layui-form-label">资源名称</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" value="${res.name! }">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">图标</label>
	    <div class="layui-input-block">
	      <input type="text" id="iconPicker" name="iconcls" lay-filter="iconPicker" class="layui-input" value="${res.iconcls!}">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">路径</label>
	    <div class="layui-input-block">
	      <input type="text" name="url" placeholder="请输入名称" autocomplete="off" class="layui-input" value="${res.url! }">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">排序</label>
	    <div class="layui-input-block">
	      <input type="text" name="seq" lay-verify="required" placeholder="请输入序号" autocomplete="off" class="layui-input" value="${res.seq! }">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">类型</label>
	    <div class="layui-input-block">
	      <input type="radio" name="type" value="1" title="菜单" checked="">
      	  <input type="radio" name="type" value="2" title="按钮">
	    </div>
	  </div>
	  <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">备注</label>
	    <div class="layui-input-block">
	      <textarea name="des" placeholder="请输入备注" class="layui-textarea">${res.des! }</textarea>
	    </div>
	  </div>
	  <div class="layui-form-item" style="display: none">
	    <div class="layui-input-block">
	      <button class="layui-btn" id="submit-btn" lay-submit>立即提交</button>
	      <button type="reset" id="reset-btn" class="layui-btn">重置</button>
	    </div>
	  </div>
	</form>
	</div>
  </body>
</html>
<script src="${ctx}/static/admin/layui/layui.js"></script>
<script src="${ctx}/static/admin/js/common.js"></script>
<script>
var treeGrid,treeId;
layui.use(['jquery','form','iconPicker'], function(){
  var $ = jQuery = layui.$;
  var form = layui.form;
  var iconPicker = layui.iconPicker;
  
  if ($(':input[name="id"]').val().length > 0) {
		$(':input[name="name"]').attr('disabled','disabled');
  }
  
  form.val("resform", {'type': '${res.type!}'});
  
  iconPicker.render({
      elem: '#iconPicker',
      type: 'fontClass',
      search: true,
      click: function (data) {
          console.log(data);
      }
  });
  
  iconPicker.checkIcon('iconPicker', '${res.iconcls!}');

  //监听提交
  form.on('submit', function(data){
	  $.post('${ctx}/sys_admin/sys/res/save', data.field, function(result) {
			if (result.success) {
				treeGrid.query(treeId,{});
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index); //再执行关闭   
			} else {
				layer.msg(result.msg);
			}
		}, 'json');
	  return false;
  });
});
</script>